# 构建阶段
FROM node:18-alpine AS build

WORKDIR /app

# 安装依赖
COPY package*.json ./
RUN npm install

# 复制源代码并构建
COPY . .
RUN npm run build

# 生产阶段
FROM nginx:alpine

# 复制构建产物
COPY --from=build /app/dist /usr/share/nginx/html

# 复制Nginx配置
COPY nginx.conf /etc/nginx/conf.d/default.conf

# 创建图片目录
RUN mkdir -p /usr/share/nginx/html/images

# 版本信息
ARG VERSION=unknown
ENV APP_VERSION=$VERSION
RUN echo $APP_VERSION > /usr/share/nginx/html/version.txt

# 暴露端口
EXPOSE 80 